package com.ioPackage;

import java.io.*;


/**
 * @ClassName FileIODemo2
 * @Description 字符输入流、输出流
 * @Author 2214361854
 * @Date 2022/2/27 22:21
 * @Version 1.0
 */
public class FileIODemo2 {
    public static void main(String[] args) throws Exception {
        System.out.println("=========字符输出流==========");
        Writer fw = new FileWriter("src\\text01.txt");
//        字符缓冲流
        BufferedWriter bw = new BufferedWriter(fw);
//        fw.write('a');
//        fw.write("你好");
//        char[] chars = "你好，中国".toCharArray();
//        fw.write(chars);
//        off从n开始，len写入n个
        bw.write("abc你好，中国",0,5);

        fw.close();
        System.out.println("写入完成");
        System.out.println("=========字符输入流==========");
        //创建字符输入流
        Reader fr = new FileReader("src\\text01.txt");
//        字符缓冲流
        BufferedReader br = new BufferedReader(fr);
//        单次读
//        System.out.println((char) fr.read());

        String line;
        //一行一行的读
        while ((line = br.readLine()) != null) {
            System.out.println(line);
        }
//        char[] buffer = new char[1024];
//        int len;
//        while ((len = br.read(buffer)) != -1) {
//            String rs = new String(buffer,0,len);
//            System.out.println(rs);
//        }
    }
}
